import { getShipList } from "@/services/ship";
import { defineStore } from "pinia";

export interface Ship {
  mmsi: string;
  id: number;
}

interface AppState {
  shipOptions: Ship[];
}

export const useAppStore = defineStore('app', {
  state: (): AppState => ({
    shipOptions: [],
  }),
  actions: {
    async updateShipOptions() {
      try {
        const res = await getShipList({
          length: 100,
          page: 1,
        });
        this.shipOptions = res.list.map(ship => ({
          mmsi: ship.mmsi,
          id: ship.id,
        }));
      } catch {
        this.shipOptions = [];
      }
    },
  }
});
